#include <iostream>
#include <unistd.h>
#include <signal.h>

void Print(const sigset_t& pending)
{
    for (int signo = 31; signo > 0; signo--)
    {
        if (sigismember(&pending, signo))
        {
            std::cout << "1";
        }
        else
        {
            std::cout << "0";
        }
    }
    std::cout << std::endl;
}

void handler(int signo)
{
    std::cout << "get a sig: " << signo << std::endl; 
    while(1)
    {
        sigset_t pending;
        sigpending(&pending);
        Print(pending);
        sleep(1);
    }
}

int main()
{
    std::cout << "pid: " << getpid() << std::endl;
    struct sigaction act, oact;
    act.sa_handler = handler;
    sigemptyset(&act.sa_mask);
    sigaddset(&act.sa_mask, 3); // 将3号信号加入sa_mask

    sigaction(2, &act, &oact);

    while(1) sleep(1);
    return 0;
}
